package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: WangHongKun
 * @Date: 2022/9/22 16:58
 * @Email: 2028911483@qq.com
 * @Phone: 18683977706
 */


@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "订单接口相关接口")
public class OrderController {

    @Autowired
    private  OrderService orderService;

    @PostMapping("/submit")
    @ApiOperation("用户下单接口")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) throws Exception {
        log.info("用户下单中完成....");
        OrderSubmitVO submitVO = orderService.submit(ordersSubmitDTO);
        return Result.success(submitVO);
    }

    @ApiOperation("订单支付接口")
    @PutMapping("/payment")
    public  Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}",ordersPaymentDTO);
        OrderPaymentVO paymentVO = orderService.payment(ordersPaymentDTO);
        return Result.success(paymentVO);
    }


    @ApiOperation("历史订单查询接口")
    @GetMapping("/historyOrders")
    public  Result<PageResult> historyOrders( OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult<OrderVO> result = orderService.historyOrders(ordersPageQueryDTO);
        return Result.success(result);
    }

    @ApiOperation("查询订单详情接口")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> QueryOrderDetail(@PathVariable Long id){
        OrderVO orderVO = orderService.QueryOrderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("取消订单接口")
    @PutMapping("/cancel/{id}")
    public Result CancelOrder(@PathVariable  Long id){
        log.info("取消的订单id：{}",id);
        orderService.CancelOrder(id);
        return Result.success();
    }

    @ApiOperation("再来一单接口")
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable  Long id){
        log.info("再来一单id：{}",id);
        orderService.repetition(id);
        return Result.success();
    }


    @ApiOperation("催单接口")
    @GetMapping("/reminder/{id}")
    public Result  reminder(@PathVariable Long id){
        log.info("催单的订单id：{}",id);
        orderService.reminder(id);
        return Result.success();
    }
}
